<?php
/**
 * CanAccessRoute
 * This is the same as the CanAccess helper except that it accepts a route and
 * route parameters rather than module/controller/action.
 *
 * @package     Visi
 * @subpackage  View Helpers
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2011 Coalition Technologies <joel@coalitiontechnologies.com>
 * @version     $Id$
 */
class Visi_View_Helper_CanAccessRoute extends Zend_View_Helper_Abstract {

    /**
     * Determine if the user has access to a specific resource by route name and
     * a set of parameters (which are converted to module/controller/action)
     */
    public function canAccessRoute($routeName, Array $params = array()) {
    
        $router = Zend_Controller_Front::getInstance()->getRouter();
        if (!$router->hasRoute($routeName)) {
            throw new Visi_Exception_RouteNotDefined("'{$routeName}' is not a defined route name.");
        } else {
            // There may be a more efficient way to do this but I don't know it...
            $route = $router->getRoute($routeName);
            // Determine the URL this routeName/param combination creates
            $url = $route->assemble($params, true);
            // Match it to a route and return all the parameters associated
            $match = $route->match($url);
            // Use parameters to check if user has access
            return $this->view->canAccess($match);
        }
    
    }

}
